package com.example.designpattern.behavioral.iterator;

import org.junit.Test;

import java.util.Iterator;

public class Client {
    @Test
    public void test() {
        MyList list = new MyList();
        // 输出：abc
        while (list.hasNext()) {
            System.out.print(list.next());
        }
    }

    @Test
    public void test1() {
        MyList list = new MyList();
        // 获取迭代器，用于遍历列表
        Iterator<String> iterator = list.iterator();
        // 输出：abc
        while (iterator.hasNext()) {
            System.out.print(iterator.next());
        }
    }

    @Test
    public void test2() {
        MyList list = new MyList();
        // 输出：abc
        for (String item : list) {
            System.out.print(item);
        }
    }


}

